
# REQUIRES: Data/Roper Data.csv

# NOTE: Uses code from Stargazer Package Updates.R instead of the published version of Stargazer. See readme.txt.

################# Dependencies #################
# source("Load Packages.R")
# source("Analysis - Roper/Cleaning.R")

################# Table S5 - Predictors of US Public Support for Withdrawal, 1946-2021 #################
# With question features and percent of options that were for withdrawal
OLS_q <- lm(percwithdraw ~  bEnemyVictory + bDeescalationOption + bOnesidedquestion + responseoptions + withdraw_ops_share,
            data = roper)

# With situation features
OLS_s <- lm(percwithdraw ~  logcas + FPR + Vietnam + Gulf_War + Afghanistan + Iraq, 
            data = roper)

# With question and situation features
OLS_qs <- lm(percwithdraw ~  bEnemyVictory + bDeescalationOption + bOnesidedquestion + responseoptions + withdraw_ops_share 
             + logcas + FPR + Vietnam + Gulf_War + Afghanistan + Iraq, 
             data = roper)

output <- stargazer(OLS_q, OLS_s, OLS_qs, title="Table S5: Replication of Observational Results with Control for Percent of Options Qualifying as Withdrawal",
                    align=TRUE, dep.var.labels=c(""), dep.var.caption="",
                    column.labels=c(" ","",""),
                    digits = 3, digits.extra = 0,
                    notes = "P-value shown in parentheses below coefficient", 
                    notes.append = FALSE,
                    report = "vc*p",
                    covariate.labels=c("Enemy Victory Framing", "Troop Reduction Option", "One-sided Question",
                                       "No. of Response Options", "Perc Withdraw Options", "Log Cumulative Casualties", "Foreign Policy Restraint",
                                       "Vietnam", "Gulf War", "Afghanistan", "Iraq", "Constant"),
                    omit.stat=c("LL","ser","f","adj.rsq"), no.space=TRUE, notes.align="c", out = "Plots/Table S5 - Predictors of US Public Support for Withdrawal, 1946-2021_R.html")

webshot("Plots/Table S5 - Predictors of US Public Support for Withdrawal, 1946-2021_R.html", "Plots/Table S5 - Predictors of US Public Support for Withdrawal, 1946-2021_R.png", zoom=5, vwidth=580, vheight=600)
# Note: Add the independent variable groups in Word and remove "_R" from the file name
# webshot("Plots/Table S5 - Predictors of US Public Support for Withdrawal, 1946-2021.html", "Plots/Table S5 - Predictors of US Public Support for Withdrawal, 1946-2021.png", zoom=5, vwidth=475, vheight=580)

rm(OLS_q, OLS_qs, OLS_s, output)
